package com.example.warehouse.service.serviceImpl;

import com.example.warehouse.entity.InStore;
import com.example.warehouse.entity.Result;
import com.example.warehouse.mapper.InStoreMapper;
import com.example.warehouse.mapper.purchaseMapper;
import com.example.warehouse.page.Page1;
import com.example.warehouse.service.InstoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InStoreServiceImpl implements InstoreService{
    @Autowired
    private InStoreMapper inStoreMapper;

    @Autowired
    private purchaseMapper purchaseMapper;

    @Transactional
    @Override
    public Result saveInStore(InStore inStore,Integer buyId) {
        inStoreMapper.insertInStore(inStore);
        purchaseMapper.setInById(buyId);
        return Result.ok("入库单添加成功");
    }

    @Override
    public Page1 QueryPage(InStore inStore, Page1 page1) {
        int count = inStoreMapper.FindInStoreCount(inStore);
        List<InStore> inStoreList = inStoreMapper.FindInStoreByPage(inStore, page1);
        page1.setPageNum(count);
        page1.setResultList(inStoreList);
        return page1;
    }

    @Transactional
    @Override
    public void confirmInstore(InStore inStore) {
        inStoreMapper.updateInstore(inStore.getStoreId());
        inStoreMapper.setInventById(inStore.getProductId(),inStore.getInNum());
    }


}

